package com.atguigu.controller;

import com.atguigu.pojo.Employee;
import com.atguigu.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: liuaojun
 * @CreateTime: 2025-02-07
 * @Description:
 * @Version: 1.0
 */
@Slf4j
@RestController
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/emp/{eid}")
    public Employee getEmployee(@PathVariable int eid) {
        Employee employeeById = employeeService.getEmployeeById(eid);
        log.info("employeeById : {}", employeeById);
        return employeeById;
    }

    @GetMapping("/emp")
    public List<Employee> getAllEmployee() {
        List<Employee> allEmployee = employeeService.getAllEmployee();
        log.info("allEmployee : {}", allEmployee);
        return allEmployee;
    }

    @PostMapping("/emp")
    public String addEmployee(@RequestBody Employee employee) {
        employeeService.addEmployee(employee);
        log.info("addEmployee : {}", employee);
        return "{info:ok}";
    }

    @PutMapping("/emp")
    public String updateEmployee(@RequestBody Employee employee) {
        employeeService.updateEmployee(employee);
        log.info("updateEmployee : {}", employee);
        return "{info:ok}";
    }

    @DeleteMapping("/emp/{id}")
    public String deleteEmployee(@PathVariable Integer id) {
        employeeService.deleteEmployee(id);
        return "{info:ok}";
    }
}
